package com.lx;

import java.util.Random;
import java.util.Scanner;

//猜数字小游戏
public class Demo3 {
    public static void main(String[]args){
        Random r=new Random();
        int a=r.nextInt(100)+1;
        System.out.println("请猜一个0-100以内的数");
        Scanner sc=new Scanner(System.in);
        int min=0;
        int max=100;
        while (true) {
            int b=sc.nextInt();
            if (b > a) {
                max = b;
                System.out.println("这个数在" + min + "与" + max + "之间");

            } else if (b < a) {
                min = b;
                System.out.println("这个数在" + min + "与" + max + "之间");

            } else {
                System.out.println("恭喜你猜中了");
                break;
            }
        }
    }
}
